<template>
    <div>
        <el-tabs :tab-position="tabPosition" v-model="activeName" @tab-click="handleClick">
            <el-tab-pane v-for="item in $dictUtils.getDictList('autoCodeBean')" :label="item.label" :name="item.value">
                <el-table
                    size="mini"
                    v-loading="loading"
                    :data="tableData"
                    style="width: 100%; margin-top: 20px"
                    border
                    :header-cell-style="{
        'background-color': '#eeeeee !important',
      }"
                    :row-class-name="tableRowClassName"
                    @sort-change="sortthiscolumn"
                >
                    <el-table-column type="index" label="序号" width="70" align="center">
                        <template slot-scope="scope">
          <span>{{
                  (page2.pageNo - 1) * page2.pageSize + scope.$index + 1
              }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="names" label="规则名称"align="center">
                    </el-table-column>
                    <el-table-column prop="example" label="规则示例"></el-table-column>
                    <el-table-column prop="maxNum" label="当前流水"></el-table-column>
                    <el-table-column prop="emptyNum" label="当前空号">
                      <template slot-scope="scope">
                      {{scope.row.emptyNum|noValue}}
                      </template>
                    </el-table-column>
                    <el-table-column prop="isFill" label="空号填补">
                        <template slot-scope="scope">
                            <span>
                                {{scope.row.isFill=='1'?'√':''}}
                            </span>

                        </template>
                    </el-table-column>
                  <el-table-column prop="address" label="操作" width="252">
                    <template slot-scope="scope">
                      <template v-for="item in $dictUtils.getDictList('state')">
                        <el-link type="primary" v-if="item.value !=='-1'&& item.value!==(scope.row.state+'')"
                                 :underline="false" @click="editState(item.value,scope.row)" :disabled="(scope.row.state===-1&& item.value==='0')||item.value==scope.row.state">{{item.label}}
                        </el-link>
                      </template>
                      <el-link type="primary" :underline="false" @click="edit(scope.row)"
                              >修改</el-link
                      >
                      <el-link
                               type="primary"
                               :underline="false"
                               @click="del(scope.row.id,scope.row.state)">删除</el-link>
                    </template>
                  </el-table-column>
                </el-table>
                <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-size="page.pageSize"
                    :current-page="page.pageNo"
                    layout="total,sizes,prev, pager, next, jumper"
                    :total="page.total"
                ></el-pagination>
            </el-tab-pane>

        </el-tabs>
    </div>
</template>
<script>
    import {getList} from '@/api/sys/authCode/AutoCodeRule.js'

    export default {
        components: {},
        data() {
            return {
                beanType: '',
                activeName: '1',
                queryForm: {
                    keyword: ''
                },

                page: {
                    pageSize: 10,
                    pageNo: 1,
                    total: 0
                },
                page2: {
                    pageSize: 10,
                    pageNo: 1,
                    total: 0
                },
                ids: '',
                tabPosition: 'left',
                tableData: [],
                tableData2: [],
                selectDatas: [],
                orderBy: {
                    name: 'update_date',
                    method: 'desc'
                },
                loading: false
            }
        },
        methods: {
            handleClick(e) {
                console.log(e)
                this.beanType = e.name
                this.getList(this.beanType,this.page, this.orderBy.name, this.orderBy.method)
            },
            // 获取列表带分页
            getList(beanType,params, orderName, orderByAORC, queryNames, queryState) {
                this.loading = true
                getList({
                    beanType: beanType,
                    pageSize: params.pageSize,
                    pageNo: params.pageNo,
                    orderBy: orderName,
                    orderByAORC: orderByAORC,
                    names: queryNames,
                    state: queryState
                }).then((res) => {
                    if (res.data.code === '200') {
                        this.tableData = res.data.result.list
                        this.page.total = res.data.result.count
                    }
                    this.loading = false
                })
            },
            // 删除
            del(ids, state) {
                if (state === 1) {
                    this.$notify.error({
                        title: '错误',
                        message: '已启用，不支持删除！'
                    });
                } else if (state === 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '已停用，不允许任何操作！'
                    });
                } else if (state === -1) {
                    this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then((res) => {
                        /*del ({
                            ids: ids
                        }).then((res) => {
                            if (res.data.code === '200') {
                                this.$message({
                                    type: 'success',
                                    message: '已删除!'
                                })
                                this.getList(this.page, this.orderBy.name, this.orderBy.method)
                            }
                        })*/
                    });
                }
            },
            // 添加
            add() {
                this.$refs.EditForm.init('add')
            },
            // 改变状态
            editState(state, row) {
                this.$confirm('是否修改状态?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((res) => {
                    /*updateState({id: row.id, state: state}).then(res => {
                        if (res.data.code === '200') {
                            this.$message({
                                type: 'success',
                                message: '状态修改成功'
                            })
                            this.getList(this.page, this.orderBy.name, this.orderBy.method)
                        }
                    })*/
                })
            },
            // 编辑
            edit(row) {
                this.$refs.EditForm.init('edit', row)
            },
            // 是否显示某列数据
            handlerCloumn(e) {
                this.checkedProps = e
                // console.log(e)
            },
            // 重置查询条件
            reset() {
                this.queryForm = {}
            },
            // 排序
            sortthiscolumn(a) {
                console.log(a)
                this.orderBy.name = a.prop
                this.page.pageNo = 1
                if (a.order === 'ascending') {
                    this.orderBy.method = 'asc'
                } else {
                    this.orderBy.method = 'desc'
                }
                this.getList(this.beanType,this.page, this.orderBy.name, this.orderBy.method)
            },
            handleSizeChange() {
            },
            handleCurrentChange(e) {
                this.page.pageNo = e
                this.getList(this.beanType,this.page, this.orderBy.name, this.orderBy.method)
                console.log(e)
            },
            tableRowClassName({row, rowIndex}) {
                if (rowIndex % 2 === 1) {
                    return 'warning-row'
                } else {
                    return 'success-row'
                }
            }
        },
        mounted() {
            this.getList(this.beanType,this.page, this.orderBy.name, this.orderBy.method)
        }
    }
</script>
<style lang="scss" scoped>
    .el-table .success-row {
        background: #f0f9eb;
    }

    ::v-deep .el-table .warning-row {
        background: #f7f7f7;
    }
</style>
